
#include "stdafx.h"
#include "ConstDef.h"
#include "ReloadCode.h"
#include "ReloadApp.h"
#include "ReloadPacket.h"

namespace reload
{
	JoinReq::JoinReq()
	{

	}

	JoinReq::~JoinReq()
	{

	}

	retT JoinReq::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(joiningPeerId_.readFromBuffer(_pBuffer));
		R(overlaySpecificData_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT JoinReq::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(joiningPeerId_.writeToBuffer(_pBuffer));
		R(overlaySpecificData_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t JoinReq::size()
	{
		return joiningPeerId_.size() + overlaySpecificData_.size();
	}

	retT JoinReq::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(joiningPeerId_.attachRootElement(_pRootElement));
		R(overlaySpecificData_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	JoinAns::JoinAns()
	{

	}

	JoinAns::~JoinAns()
	{

	}

	retT JoinAns::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(overlaySpecificData_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT JoinAns::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(overlaySpecificData_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t JoinAns::size()
	{
		return overlaySpecificData_.size();
	}

	retT JoinAns::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(overlaySpecificData_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	LeaveReq::LeaveReq()
	{

	}

	LeaveReq::~LeaveReq()
	{

	}

	retT LeaveReq::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(leavingPeerId_.readFromBuffer(_pBuffer));
		R(overlaySpecificData_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT LeaveReq::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(leavingPeerId_.writeToBuffer(_pBuffer));
		R(overlaySpecificData_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t LeaveReq::size()
	{
		return leavingPeerId_.size() + overlaySpecificData_.size();
	}

	retT LeaveReq::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(leavingPeerId_.attachRootElement(_pRootElement));
		R(overlaySpecificData_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	RouteQueryReq::RouteQueryReq()
	:sendUpdate_(Boolean_False)
	{

	}

	RouteQueryReq::~RouteQueryReq()
	{
		sendUpdate_ = Boolean_False;
	}

	retT RouteQueryReq::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(_pBuffer->ntohRead(sendUpdate_));
		R(destination_.readFromBuffer(_pBuffer));
		R(overlaySpecificData_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT RouteQueryReq::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(_pBuffer->htonWrite(sendUpdate_));
		R(destination_.writeToBuffer(_pBuffer));
		R(overlaySpecificData_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t RouteQueryReq::size()
	{
		return sizeof(sendUpdate_) + destination_.size() + overlaySpecificData_.size();
	}

	retT RouteQueryReq::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(destination_.attachRootElement(_pRootElement));
		R(overlaySpecificData_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	ProbeReq::ProbeReq()
	{

	}

	ProbeReq::~ProbeReq()
	{

	}

	retT ProbeReq::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(requestedInfo_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT ProbeReq::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(requestedInfo_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t ProbeReq::size()
	{
		return requestedInfo_.size();
	}

	retT ProbeReq::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(requestedInfo_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	ProbeInformationData::ProbeInformationData()
	:responsiblePpb_(0),numResources_(0),uptime_(0),pType_(NULL)
	{

	}

	ProbeInformationData::~ProbeInformationData()
	{
		responsiblePpb_ = 0;
		numResources_ = 0;
		uptime_ = 0;
		pType_ = NULL;
	}

	retT ProbeInformationData::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		if(pType_)
		{
			switch(*pType_)
			{
			case ProbeInformationType_ResponsibleSet:R(_pBuffer->ntohRead(responsiblePpb_));break;
			case ProbeInformationType_NumResources:R(_pBuffer->ntohRead(numResources_));break;
			case ProbeInformationType_Uptime:R(_pBuffer->ntohRead(uptime_));break;
			default:
				{
					if(pLength_)
					{
						R(_pBuffer->consume(*pLength_));
					}
					else
						RET(ERROR_COMMON_PTR_NULL);
					RET(INFO_PROTOCOL_RELOAD_PROBEINFORMATIONDATA_UNKNOWN_TYPE);
				}
			}
		}
		else
			RET(ERROR_COMMON_PTR_NULL);
		READFROMBUFFER_END;
	}

	retT ProbeInformationData::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		if(pType_)
		{
			switch(*pType_)
			{
			case ProbeInformationType_ResponsibleSet:R(_pBuffer->htonWrite(responsiblePpb_));break;
			case ProbeInformationType_NumResources:R(_pBuffer->htonWrite(numResources_));break;
			case ProbeInformationType_Uptime:R(_pBuffer->htonWrite(uptime_));break;
			default:
				{
					if(pLength_)
					{
						R(_pBuffer->produce(*pLength_));
					}
					else
						RET(ERROR_COMMON_PTR_NULL);
					RET(INFO_PROTOCOL_RELOAD_PROBEINFORMATIONDATA_UNKNOWN_TYPE);
				}
			}
		}
		else
			RET(ERROR_COMMON_PTR_NULL);
		WRITETOBUFFER_END;
	}

	std::size_t ProbeInformationData::size()
	{
		std::size_t totalSize = 0;
		if(pType_)
		{
			switch(*pType_)
			{
			case ProbeInformationType_ResponsibleSet:totalSize += sizeof(responsiblePpb_);break;
			case ProbeInformationType_NumResources:totalSize += sizeof(numResources_);break;
			case ProbeInformationType_Uptime:totalSize += sizeof(uptime_);break;
			default:
				{
					if(pLength_)
					{
						totalSize += *pLength_;
					}
					break;;
				}
			}
		}
		return totalSize;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	ProbeInformation::ProbeInformation()
	:type_(ProbeInformationType_Reserved),length_(0)
	{
		value_.pType_ = &type_;
		value_.pLength_ = &length_;
	}

	ProbeInformation::ProbeInformation( const ProbeInformation& _probeInformation )
	:PacketElement(_probeInformation),type_(_probeInformation.type_),length_(_probeInformation.length_),value_(_probeInformation.value_)
	{
		value_.pType_ = &type_;
		value_.pLength_ = &length_;
	}

	ProbeInformation::~ProbeInformation()
	{
		type_ = ProbeInformationType_Reserved;
		length_ = 0;
	}

	retT ProbeInformation::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(_pBuffer->ntohRead(type_));
		R(_pBuffer->ntohRead(length_));
		R(value_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT ProbeInformation::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(_pBuffer->htonWrite(type_));
		R(_pBuffer->htonWrite(length_));
		R(value_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t ProbeInformation::size()
	{
		return sizeof(type_) + sizeof(length_) + value_.size();
	}

	retT ProbeInformation::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(value_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	const ProbeInformation& ProbeInformation::operator=( const ProbeInformation& _probeInformation )
	{
		PacketElement::operator=(_probeInformation);
		type_ = _probeInformation.type_;
		length_ = _probeInformation.length_;
		value_ = _probeInformation.value_;
		value_.pType_ = &type_;
		value_.pLength_ = &length_;
		return *this;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	ProbeAns::ProbeAns()
	{

	}

	ProbeAns::~ProbeAns()
	{

	}

	retT ProbeAns::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(probeInfo_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT ProbeAns::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(probeInfo_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t ProbeAns::size()
	{
		return probeInfo_.size();
	}

	retT ProbeAns::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(probeInfo_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	IceExtension::IceExtension()
	{

	}

	IceExtension::~IceExtension()
	{

	}

	retT IceExtension::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(name_.readFromBuffer(_pBuffer));
		R(value_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT IceExtension::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(name_.writeToBuffer(_pBuffer));
		R(value_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t IceExtension::size()
	{
		return name_.size() + value_.size();
	}

	retT IceExtension::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(name_.attachRootElement(_pRootElement));
		R(value_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	IceCandidate::IceCandidate()
	:overlayLink_(OverlayLinkType_ReservedOverlayLink),priority_(0),type_(CandType_ReservedCand)
	{

	}

	IceCandidate::~IceCandidate()
	{
		overlayLink_ = OverlayLinkType_ReservedOverlayLink;
		priority_ = 0;
		type_ = CandType_ReservedCand;
	}

	retT IceCandidate::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(addrPort_.readFromBuffer(_pBuffer));
		R(_pBuffer->ntohRead(overlayLink_));
		R(foundation_.readFromBuffer(_pBuffer));
		R(_pBuffer->ntohRead(priority_));
		R(_pBuffer->ntohRead(type_));
		switch(type_)
		{
		case CandType_Host:break;/* Nothing */
		case CandType_Srflx:
		case CandType_Prflx:
		case CandType_Relay:R(relAddrPort_.readFromBuffer(_pBuffer));break;
		default:RET(INFO_PROTOCOL_RELOAD_ICECANDIDATE_UNKNOWN_TYPE);
		};
		R(extensions_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT IceCandidate::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(addrPort_.writeToBuffer(_pBuffer));
		R(_pBuffer->htonWrite(overlayLink_));
		R(foundation_.writeToBuffer(_pBuffer));
		R(_pBuffer->htonWrite(priority_));
		R(_pBuffer->htonWrite(type_));
		switch(type_)
		{
		case CandType_Host:break;/* Nothing */
		case CandType_Srflx:
		case CandType_Prflx:
		case CandType_Relay:R(relAddrPort_.writeToBuffer(_pBuffer));break;
		default:RET(INFO_PROTOCOL_RELOAD_ICECANDIDATE_UNKNOWN_TYPE);
		};
		R(extensions_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t IceCandidate::size()
	{
		std::size_t totalSize = 0;
		totalSize += addrPort_.size();
		totalSize += sizeof(overlayLink_);
		totalSize += foundation_.size();
		totalSize += sizeof(priority_);
		totalSize += sizeof(type_);
		switch(type_)
		{
		case CandType_Host:break;/* Nothing */
		case CandType_Srflx:
		case CandType_Prflx:
		case CandType_Relay:totalSize += relAddrPort_.size();break;
		default:break;
		};
		totalSize += extensions_.size();
		return totalSize;
	}

	retT IceCandidate::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(addrPort_.attachRootElement(_pRootElement));
		R(foundation_.attachRootElement(_pRootElement));
		R(relAddrPort_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	AttachReqAns::AttachReqAns()
	:sendUpdate_(Boolean_False)
	{

	}

	AttachReqAns::~AttachReqAns()
	{
		sendUpdate_ = Boolean_False;
	}

	retT AttachReqAns::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(ufrag_.readFromBuffer(_pBuffer));
		R(password_.readFromBuffer(_pBuffer));
		R(role_.readFromBuffer(_pBuffer));
		R(candidates_.readFromBuffer(_pBuffer));
		R(_pBuffer->ntohRead(sendUpdate_));
		READFROMBUFFER_END;
	}

	retT AttachReqAns::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(ufrag_.writeToBuffer(_pBuffer));
		R(password_.writeToBuffer(_pBuffer));
		R(role_.writeToBuffer(_pBuffer));
		R(candidates_.writeToBuffer(_pBuffer));
		R(_pBuffer->htonWrite(sendUpdate_));
		WRITETOBUFFER_END;
	}

	std::size_t AttachReqAns::size()
	{
		return ufrag_.size() + password_.size() + role_.size() + candidates_.size() + sizeof(sendUpdate_);
	}

	retT AttachReqAns::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(ufrag_.attachRootElement(_pRootElement));
		R(password_.attachRootElement(_pRootElement));
		R(role_.attachRootElement(_pRootElement));
		R(candidates_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	AppAttachReq::AppAttachReq()
	:application_(0)
	{

	}

	AppAttachReq::~AppAttachReq()
	{
		application_ = 0;
	}

	retT AppAttachReq::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(ufrag_.readFromBuffer(_pBuffer));
		R(password_.readFromBuffer(_pBuffer));
		R(_pBuffer->ntohRead(application_));
		R(role_.readFromBuffer(_pBuffer));
		R(candidates_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT AppAttachReq::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(ufrag_.writeToBuffer(_pBuffer));
		R(password_.writeToBuffer(_pBuffer));
		R(_pBuffer->htonWrite(application_));
		R(role_.writeToBuffer(_pBuffer));
		R(candidates_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t AppAttachReq::size()
	{
		return ufrag_.size() + password_.size() + sizeof(application_) + role_.size() + candidates_.size();
	}

	retT AppAttachReq::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(ufrag_.attachRootElement(_pRootElement));
		R(password_.attachRootElement(_pRootElement));
		R(role_.attachRootElement(_pRootElement));
		R(candidates_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	AppAttachAns::AppAttachAns()
	:application_(0)
	{

	}

	AppAttachAns::~AppAttachAns()
	{
		application_ = 0;
	}

	retT AppAttachAns::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(ufrag_.readFromBuffer(_pBuffer));
		R(password_.readFromBuffer(_pBuffer));
		R(_pBuffer->ntohRead(application_));
		R(role_.readFromBuffer(_pBuffer));
		R(candidates_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT AppAttachAns::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(ufrag_.writeToBuffer(_pBuffer));
		R(password_.writeToBuffer(_pBuffer));
		R(_pBuffer->htonWrite(application_));
		R(role_.writeToBuffer(_pBuffer));
		R(candidates_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t AppAttachAns::size()
	{
		return ufrag_.size() + password_.size() + sizeof(application_) + role_.size() + candidates_.size();
	}

	retT AppAttachAns::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(ufrag_.attachRootElement(_pRootElement));
		R(password_.attachRootElement(_pRootElement));
		R(role_.attachRootElement(_pRootElement));
		R(candidates_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	PingReq::PingReq()
	{

	}

	PingReq::~PingReq()
	{

	}

	retT PingReq::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(padding_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT PingReq::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(padding_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t PingReq::size()
	{
		return padding_.size();
	}

	retT PingReq::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(padding_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	PingAns::PingAns()
	:responseId_(0),time_(0)
	{

	}

	PingAns::~PingAns()
	{
		responseId_ = 0;
		time_ = 0;
	}

	retT PingAns::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(_pBuffer->ntohRead(responseId_));
		R(_pBuffer->ntohRead(time_));
		READFROMBUFFER_END;
	}

	retT PingAns::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(_pBuffer->htonWrite(responseId_));
		R(_pBuffer->htonWrite(time_));
		WRITETOBUFFER_END;
	}

	std::size_t PingAns::size()
	{
		return sizeof(responseId_) + sizeof(time_);
	}

	/////////////////////////////////////////////////////////////////////////////////////

	ConfigUpdateReq::ConfigUpdateReq()
	:type_(ConfigUpdateType_ReservedConfigUpdate),length_(0)
	{

	}

	ConfigUpdateReq::~ConfigUpdateReq()
	{
		type_ = ConfigUpdateType_ReservedConfigUpdate;
		length_ = 0;
	}

	retT ConfigUpdateReq::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(_pBuffer->ntohRead(type_));
		R(_pBuffer->ntohRead(length_));
		switch(type_)
		{
		case ConfigUpdateType_Config:R(configData_.readFromBuffer(_pBuffer));break;
		case ConfigUpdateType_Kind:R(kinds_.readFromBuffer(_pBuffer));break;
		default:RET(INFO_PROTOCOL_RELOAD_CONFIGUPDATEREQ_UNKNOWN_TYPE);
		}
		READFROMBUFFER_END;
	}

	retT ConfigUpdateReq::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(_pBuffer->htonWrite(type_));
		R(_pBuffer->htonWrite(length_));
		switch(type_)
		{
		case ConfigUpdateType_Config:R(configData_.writeToBuffer(_pBuffer));break;
		case ConfigUpdateType_Kind:R(kinds_.writeToBuffer(_pBuffer));break;
		default:RET(INFO_PROTOCOL_RELOAD_CONFIGUPDATEREQ_UNKNOWN_TYPE);
		}
		WRITETOBUFFER_END;
	}

	std::size_t ConfigUpdateReq::size()
	{
		std::size_t totalSize = 0;
		totalSize += sizeof(type_);
		totalSize += sizeof(length_);
		switch(type_)
		{
		case ConfigUpdateType_Config:totalSize += configData_.size();break;
		case ConfigUpdateType_Kind:totalSize += kinds_.size();break;
		default:totalSize += length_;break;
		}
		return totalSize;
	}

	retT ConfigUpdateReq::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(configData_.attachRootElement(_pRootElement));
		R(kinds_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	ConfigUpdateAns::ConfigUpdateAns()
	{

	}

	ConfigUpdateAns::~ConfigUpdateAns()
	{

	}

	retT ConfigUpdateAns::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		READFROMBUFFER_END;
	}

	retT ConfigUpdateAns::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		WRITETOBUFFER_END;
	}

	std::size_t ConfigUpdateAns::size()
	{
		return 0;
	}

	/////////////////////////////////////////////////////////////////////////////////////

	FramedMessage::FramedMessage()
	:type_(FramedMessageType_Data),sequence_(0),ackSequence_(0),received_(0)
	{

	}

	FramedMessage::~FramedMessage()
	{
		type_ = FramedMessageType_Data;
		sequence_ = 0;
		ackSequence_ = 0;
		received_ = 0;
	}

	retT FramedMessage::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(_pBuffer->ntohRead(type_));
		switch(type_)
		{
		case FramedMessageType_Data:R(_pBuffer->ntohRead(sequence_));R(message_.readFromBuffer(_pBuffer));break;
		case FramedMessageType_Ack:R(_pBuffer->ntohRead(ackSequence_));R(_pBuffer->ntohRead(received_));break;
		default:RET(INFO_PROTOCOL_RELOAD_FRAMEDMESSAGE_UNKNOWN_TYPE);
		}
		READFROMBUFFER_END;
	}

	retT FramedMessage::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(_pBuffer->htonWrite(type_));
		switch(type_)
		{
		case FramedMessageType_Data:R(_pBuffer->htonWrite(sequence_));R(message_.writeToBuffer(_pBuffer));break;
		case FramedMessageType_Ack:R(_pBuffer->htonWrite(ackSequence_));R(_pBuffer->htonWrite(received_));break;
		default:RET(INFO_PROTOCOL_RELOAD_FRAMEDMESSAGE_UNKNOWN_TYPE);
		}
		WRITETOBUFFER_END;
	}

	std::size_t FramedMessage::size()
	{
		std::size_t totalSize = 0;
		totalSize += sizeof(type_);
		switch(type_)
		{
		case FramedMessageType_Data:totalSize += sizeof(sequence_);totalSize += message_.size();break;
		case FramedMessageType_Ack:totalSize += sizeof(ackSequence_);totalSize += sizeof(received_);break;
		default:break;
		}
		return totalSize;
	}

	retT FramedMessage::attachRootElement( boost::weak_ptr<asyframe::PacketElement> _pRootElement )
	{
		R(asyframe::PacketElement::attachRootElement(_pRootElement));
		R(message_.attachRootElement(_pRootElement));
		RETSUCCESS;
	}
} /*namespace reload*/
